package cn.tedu.mintmall.controller;

import cn.tedu.mintmall.dto.CategoryAddNewDTO;
import cn.tedu.mintmall.entity.Category;
import cn.tedu.mintmall.restful.JsonResult;
import cn.tedu.mintmall.service.ICaegoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Locale;

@RestController
@RequestMapping("/category")
@Api(tags = "后台类别管理")
public class CategoryController {
    @Autowired
    private ICaegoryService caegoryService;

    @PostMapping("/add-new")
    @ApiOperation("添加类别")
    public JsonResult<Void> addNew(@Validated CategoryAddNewDTO categoryAddNewDTO) {
        caegoryService.addNew(categoryAddNewDTO);
        return JsonResult.ok("添加成功");
    }
    @GetMapping("/select/all")
    @ApiOperation("查询所有")
    public JsonResult<List<Category>> selectAll(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "pageSize",defaultValue = "2")Integer pageSize
    ){
        List<Category> categories = caegoryService.selectAll(page, pageSize);
        return JsonResult.ok("查询成功",categories);
    }

    @PostMapping("/delete")
    @ApiOperation("删除订单")
    public JsonResult delete(Long id){
        caegoryService.deleteById(id);
        return JsonResult.ok("删除成功");
    }

    @PostMapping("/upda")
    @ApiOperation("修改订单")
    public JsonResult update(Category category){
        caegoryService.updateCategoryById(category);
        return JsonResult.ok("修改完成");
    }


}
